package com.xiaoyun.activiti02;


import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.apache.commons.io.IOUtils;

import java.io.*;
import java.util.List;

/**
 * 从Activiti 的act_ge_byte表中读取两个资源文件
 * <p>
 * <p>
 * 用户想查看这个请假流程具体有那些步骤要走
 */
public class QueryBpmnFile {

    public static void main(String[] args) throws IOException {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        RepositoryService repositoryService = processEngine.getRepositoryService();

        ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();

        ProcessDefinition processDefinition = processDefinitionQuery
                .processDefinitionKey("holiday").singleResult();

        String deploymentId = processDefinition.getDeploymentId();

        InputStream pngIs = repositoryService.getResourceAsStream(deploymentId, processDefinition.getDiagramResourceName());

        InputStream bmpnIs = repositoryService.getResourceAsStream(deploymentId, processDefinition.getResourceName());

        OutputStream pngOs = new FileOutputStream("E:\\javaUtil\\" + processDefinition.getDiagramResourceName());

        OutputStream bpmnOs = new FileOutputStream("E:\\javaUtil\\" + processDefinition.getResourceName());

        IOUtils.copy(pngIs, pngOs);
        IOUtils.copy(bmpnIs, bpmnOs);

        pngOs.close();
        bpmnOs.close();
        pngIs.close();
        bmpnIs.close();

    }
}
